package com.xmsx.back.controller.index;

import com.xmsx.back.pojo.*;
import com.xmsx.back.results.Result;
import com.xmsx.back.service.index.GradService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/grad")
public class GradController {

    @Autowired
    GradService gradService;

    /**
     * 查询年份列表
     *
     * @return
     */
    @GetMapping("/yearList")
    public Result<List<Integer>> getYearList() {
        List<Integer> yearList = gradService.getYearList();
        if (!yearList.isEmpty()) {
            return Result.success(yearList);
        } else {
            return Result.error("不存在yearList");
        }
    }

    /**
     * 查询毕业去向数据
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/direction")
    public Result<ResultFirst<Element>> getDirectionData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultFirst<Element> rf = gradService.getDirectionData(start, end);
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询升学单位数据
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/school")
    public Result<ResultSecond<Element>> getSchoolData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultSecond<Element> rs = gradService.getSchoolData(start, end);
        if (rs != null) {
            return Result.success(rs);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询单位性质分布
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/org_kind")
    public Result<ResultFirst<Element>> getOrgKindData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultFirst<Element> rf = gradService.getOrgKindData(start, end);
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询单位行业分布
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/org_industry")
    public Result<ResultFirst<Element>> getOrgIndustryData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultFirst<Element> rf = gradService.getOrgIndustryData(start, end);
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询就业单位分布
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/org_name")
    public Result<ResultFirst<Element>> getOrgNameData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultFirst<Element> rf = gradService.getOrgNameData(start, end);
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询整体就业单位分布
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/org_name_total")
    public Result<List<ElementTotal>> getOrgNameDataTotal(@RequestParam("start") int start, @RequestParam("end") int end) {
        List<ElementTotal> le = gradService.getOrgNameDataTotal(start, end);
        if (le != null && le.size() != 0) {
            return Result.success(le);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 查询就业地域分布
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/org_location")
    public Result<ResultFirst<Element>> getOrgLocationData(@RequestParam("start") int start, @RequestParam("end") int end) {
        ResultFirst<Element> rf = gradService.getOrgLocationData(start, end);
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 首页热门城市
     *
     * @return
     */
    @GetMapping("/city")
    public Result<List<Element>> getLatestHotCity() {
        List<Element> le = gradService.getLatestHotCity();
        if (le != null && le.size() != 0) {
            return Result.success(le);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 首页毕业生数量和就业率变化
     *
     * @return
     */
    @GetMapping("/rate")
    public Result<ResultFirst<Rate>> getTotalAndRate() {
        ResultFirst<Rate> rf = new ResultFirst<>();
        rf.setBachelor(gradService.getTotalAndRateByEdu("本科生毕业"));
        rf.setMaster(gradService.getTotalAndRateByEdu("硕士生毕业"));
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 历年变化-升学率
     *
     * @return
     */
    @GetMapping("/upgradeRate")
    public Result<List<Rate>> getUpgradeBachelorRate() {
        List<Rate> lr = gradService.getUpgradeBachelorRate();
        if (lr != null) {
            return Result.success(lr);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 历年变化-就业率
     *
     * @return
     */
    @GetMapping("/employedRate")
    public Result<List<Rate>> getEmployedRate() {
        List<Rate> lr = gradService.getEmployedRate();
        if (lr != null) {
            return Result.success(lr);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 历年变化-毕业生就业留鲁发展率
     *
     * @return
     */
    @GetMapping("/employedAtSD")
    public Result<ResultFirst<Rate>> getContractEmployedRate() {
        ResultFirst<Rate> rf = new ResultFirst<>();
        rf.setBachelor(gradService.getContractEmployedAtSDRateByEdu("本科生毕业"));
        rf.setMaster(gradService.getContractEmployedAtSDRateByEdu("硕士生毕业"));
        if (rf != null) {
            return Result.success(rf);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 导出就业质量报告所需数据
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/documentData")
    public Result<DocumentData> getDocumentData(@RequestParam("start") int start, @RequestParam("end") int end) {
        DocumentData documentData = gradService.getDocumentDataByYear(start, end);
        if (documentData != null) {
            return Result.success(documentData);
        } else {
            return Result.error("查询失败");
        }
    }

    /**
     * 回生源地发展比例
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/backToOrigin")
    public Result<List<Rate>> getBackToOriginRate(@RequestParam("start") int start, @RequestParam("end") int end) {
        List<Rate> lr = gradService.getBackToOriginData(start, end);
        if (lr != null) {
            return Result.success(lr);
        } else {
            return Result.error("查询失败");
        }
    }
}
